package com.acme.domain.bank;

import java.io.Serializable;

import com.acme.domain.account.Account;

public class Client implements Serializable {

    Account [] accounts;
    int accountsNum;
    String name;

	public Client(String name, Gender gender) {
        accounts = new Account[10];
        accountsNum = 0;
	}

	public void addAccount(Account account) {
        accounts[accountsNum] = account;
        accountsNum++;
	}

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean equals(Object object)
    {
        if (this == object) return true;
        if (this.getClass() != object.getClass()) return false;
        if (object == null) return false;
        if (this.getAccountsNum() != ((Client)object).getAccountsNum()) return false;
        Account [] objAccounts = ((Client)object).getAccounts();
        for (int i = 0; i < this.accountsNum; i++)
            if (!accounts[i].equals(objAccounts[i])) return false;
        return true;
    }

    public Account[] getAccounts() {
        return accounts;
    }

    public int hashCode()
    {
        int hash = 137;
        for (int i = 0; i < accountsNum; i++){
            hash *= (((int)accounts[i].getBalance()) * 353) % 2557;
        }
        return hash;
    }

    public int getAccountsNum() {
        return accountsNum;
    }

    @Override
    public String toString() {
        StringBuffer result = new StringBuffer("Client with " + accountsNum +" accounts:/n");
        for (int i = 0; i < accountsNum; i++){
            result.append("    " + accounts[i].toString() + "/n");
        }
        return result.toString();
    }
}
